using System;
using L=Science.Physics.GeneralPhysics;

namespace Serway.Chapter15
{
	/// <summary>
	/// Example04: Oscillations on a Horizontal Surface.
	/// A 0.500 kg cart connected to a light spring for which 
	/// the force constant is 20.0 N/m oscillates on a horizontal, 
	/// frictionless air track.
	/// (A) Calculate the total energy of the system and the maximum
	/// speed of the cart if the amplitude of the motion is 3.00 cm.
	/// E = 9 \times 10^{-3} J
	/// v_{max} = 0.19 m/s
	/// (B) What is the velocity of the cart when the position 
	/// is 2.00 cm?
	/// v = \pm 0.141 m/s
	/// (C) Compute the kinetic and potential energies of 
	/// the system when the position is 2.00 cm.
	/// K = 5 \times 10^{-3} J
	/// U = 4 \times 10^{-3} J
	/// </summary>
	public class Example04
	{
		public Example04()
		{
		}
		private string result;
		public string Result
		{
			get{return result;}
		}
		public void Compute()
		{
			L.SimpleHarmonicMotion shm = new L.SimpleHarmonicMotion();
			shm.Mass = 0.5;
			shm.SpringForceConstant = 20.0;
			shm.Amplitude = 0.03;
			//(A)
			result+=Convert.ToString(shm.TotalEnergy)+"\r\n";
            shm.FindAngularFrequencyOfMassSpringSystem();
			result+=Convert.ToString(shm.VelocityMaximum)+"\r\n";
			//(B)
    		L.Time t = new L.Time();
			t.s = Math.Acos(0.02/0.03)/shm.AngularFrequency;
			result+=Convert.ToString(shm.Velocity(t))+"\r\n";
			//(C)
			result+=Convert.ToString(shm.KineticEnergy(t))+"\r\n";
			result+=Convert.ToString(shm.PotentialEnergy(t))+"\r\n";
		}
	}
}
